<%@ page contentType="text/html;charset=UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="static/element/index.css">
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title></title>
    <style>
        .fail .layui-layer-content {
            background-color: brown;
            color: #eee;
            width: 400px;
            height: 30px;
            text-align: center;
        }

        .succeed .layui-layer-content {
            background-color: #0061A8;
            color: #eee;
            width: 400px;
            height: 30px;
            text-align: center;
        }

        * {
            padding: 0;
            margin: 0;
        }

        html {
            overflow-y: hidden;
        }

        body, html {
            width: 100%;
            height: 100%;
        }

        body {
            display: flex;
            flex-flow: column;
        }

        .fheader {
            height: 1%;
            min-height: 50px;
        }

        .fsection {
            display: flex;
            flex-flow: row;
            min-height: 0;
        }

        .farticle {
            flex: 1;
            padding: 1px;
            height: 100%;
            overflow: scroll;
            float: left;
            overflow-x: hidden;
            overflow-y: hidden;
        }

        .el-table__cell {
            padding: 5px 0 !important;
        }

        .el-table__body tr:hover > td {
            background-color: #DFDFDF !important;
            cursor: default
        }

    </style>
</head>
<body>
<div id="app">
    <div class="fheader" style="padding: 0;margin: 0 ">
        <el-row>
            <div class="l" style="margin-left: 20px; margin-top: 8px">
                <el-select v-model="sh" placeholder="请选择商户" size="medium" style="width: 120px; border: 0">
                    <el-option
                            v-for="item in tableShang"
                            :key="item.VALUE02"
                            :label="item.VALUE03"
                            :value="item.VALUE02">
                    </el-option>
                </el-select>
            </div>
            <div class="l" style="margin-left: 8px; padding-top: 5px">
                <el-date-picker
                        v-model="value2"
                        type="datetimerange"
                        :picker-options="pickerOptions"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        format="yyyy-MM-dd HH:mm"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        align="right">
                </el-date-picker>
            </div>
            <a class="btn btn-success radius l" style="line-height:1.6em;margin-top:10px; margin-left: 10px"
               @click="fGetinfo()" title="查询" v-loading.fullscreen.lock="fullscreenLoading">查询</a>
            <span class="r" style="padding-top: 6px;">共有数据：[<strong id="count">{{iiCount}}</strong> 条]</span>
            <a class="btn btn-success radius l" style="line-height:1.6em;margin-top:10px; margin-left: 10px"
               @click="fExport()" title="导出excel表单">导出excel表单</a>
        </el-row>
    </div>
    <div class="fsection">
        <div class="farticle">
            <div style="height: 100%; width: 100%; overflow: scroll; float: left; overflow-x: hidden;">
                <el-table :data="tableData" stripe border style="width: 100%;" :height="tableHeightL" empty-text="没有数据" :header-cell-style="tableHeaderCellStyleL" :cell-style="tableCellStyleL">
                    <el-table-column prop="VALUE01" label="日期" width="220"></el-table-column>
                    <el-table-column prop="VALUE08" label="总消费" width="120">
                        <template slot-scope="scope">
                            <span v-if="scope.row.VALUE08 === '0.00'"></span>
                            <span v-else>{{scope.row.VALUE08}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="VALUE09" label="总人次" width="90">
                        <template slot-scope="scope">
                            <span v-if="scope.row.VALUE09 === '0'"></span>
                            <span v-else>{{scope.row.VALUE09}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="VALUE02" label="早餐消费" width="120">
                        <template slot-scope="scope">
                            <span v-if="scope.row.VALUE02 === '0.00'"></span>
                            <span v-else>{{scope.row.VALUE02}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="VALUE03" label="早餐人次" width="90">
                        <template slot-scope="scope">
                            <span v-if="scope.row.VALUE03 === '0'"></span>
                            <span v-else>{{scope.row.VALUE03}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="VALUE04" label="午餐消费" width="120">
                        <template slot-scope="scope">
                            <span v-if="scope.row.VALUE04 === '0.00'"></span>
                            <span v-else>{{scope.row.VALUE04}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="VALUE05" label="午餐人次" width="90">
                        <template slot-scope="scope">
                            <span v-if="scope.row.VALUE05 === '0'"></span>
                            <span v-else>{{scope.row.VALUE05}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="VALUE06" label="晚餐消费" width="120">
                        <template slot-scope="scope">
                            <span v-if="scope.row.VALUE06 === '0.00'"></span>
                            <span v-else>{{scope.row.VALUE06}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="VALUE07" label="晚餐人次" width="90">
                        <template slot-scope="scope">
                            <span v-if="scope.row.VALUE07 === '0'"></span>
                            <span v-else>{{scope.row.VALUE07}}</span>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>
    </div>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/Layui_30023/layui.all.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/layui_exts/excel.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="static/axios.min.js"></script>
<script type="text/javascript" src="./static/vue"></script>
<script src="static/element/index.js"></script>
<script type="text/javascript">
    let vm = new Vue({
        el: '#app',
        data: {
            dateBb: '',
            dateEe: '',
            tableData: [],      //--主体信息表
            tableShang: [],
            sh: '',
            iiCount: '',
            pickerOptions: {
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        const end = new Date(new Date().setHours(23, 59, 59))
                        const start = new Date(new Date().setHours(0, 0, 0, 0))
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '昨天',
                    onClick(picker) {
                        const end = new Date(new Date(new Date().getTime() - 24 * 60 * 60 * 1000).setHours(23, 59, 59))
                        const start = new Date(new Date(new Date().getTime() - 24 * 60 * 60 * 1000).setHours(0, 0, 0))
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '前天',
                    onClick(picker) {
                        const end = new Date(new Date(new Date().getTime() - 48 * 60 * 60 * 1000).setHours(23, 59, 59))
                        const start = new Date(new Date(new Date().getTime() - 48 * 60 * 60 * 1000).setHours(0, 0, 0))
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近7天',
                    onClick(picker) {
                        const end = new Date(new Date().setHours(23, 59, 59))
                        const start = new Date(new Date(new Date().getTime() - 7 * 24 * 60 * 60 * 1000).setHours(0, 0, 0))
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '本月',
                    onClick(picker) {
                        let date = new Date();
                        let year = date.getFullYear()
                        let month = parseInt(date.getMonth());
                        const start = new Date(year, month, 1, 0, 0, 0);
                        const end = new Date(new Date().setHours(23, 59, 59))
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            value2: [],
            fullscreenLoading:false
        },
        methods: {

            tableHeaderCellStyleL({row, column, rowIndex, columnIndex}) {
                let cellStyle1;

                cellStyle1 = "color: #fff;" +
                    "background:#4F4F4F;" +
                    "text-align:center;" +
                    "font-size:12px"

                return cellStyle1
            },

            tableCellStyleL({row, column, rowIndex, columnIndex}) {
                let cellStyle1;

                if (rowIndex === this.iiCount - 0) {
                    cellStyle1 = "text-align:center;" +
                        "padding:8px 1px 8px;" +
                        "font-size:14px;" +
                        "font-weight:bold;"
                } else {
                    cellStyle1 = "text-align:center;" +
                        "padding:8px 1px 8px;" +
                        "font-size:12px;"
                }
                return cellStyle1;
            },

            fExport(){
                const excel = layui.excel;
                let data = excel.filterExportData(this.tableData, [
                    'VALUE01','VALUE02','VALUE03','VALUE04','VALUE05','VALUE06','VALUE07','VALUE08','VALUE09'
                ]);

                //--为头部定义中文名称
                data.unshift({VALUE01: '日期',
                            VALUE02: '早餐消费',
                            VALUE03: '早餐人次',
                            VALUE04: '午餐消费',
                            VALUE05: '午餐人次',
                            VALUE06: '晚餐消费',
                            VALUE07: '晚餐人次',
                            VALUE08: '总计消费',
                            VALUE09: '总计人次'});
                excel.exportExcel({
                    sheet1: data
                }, '消费汇总表_按餐次.xlsx', 'xlsx');
            },

            fGetinfo() {
                if (this.value2.length === 0) {
                    layer.msg('<span style="font-size:26px; line-height: 30px">请选择查询的起止时间!</span>', {time: 2000, skin: 'fail'});
                    return
                }
                this.dateBb = this.dateFormat(this.value2[0])
                this.dateEe = this.dateFormat(this.value2[1])

                this.fullscreenLoading=true
                let self = this
                let params = new URLSearchParams();
                params.append('CMD', "BO");
                params.append('VALUE01', this.dateBb);
                params.append('VALUE02', this.dateEe);
                params.append('VALUE03', this.sh);
                axios.post('/f_wscl/com2', params)
                    .then(function (res) {
                        let {db1, db2} = res.data
                        self.tableData = db1
                        self.iiCount = db2[0].VALUE01
                    })
                    .catch(function (error) {
                        layer.msg('<span style="font-size:24px; line-height: 30px">网络异常错误!</span>', {time: 2000, skin: 'fail'});
                    }).finally(function (){
                    self.fullscreenLoading=false
                });
            },

            dateFormat: function (time) {
                const date = new Date(time);
                const year = date.getFullYear();
                /* 在日期格式中，月份是从0开始的，因此要加0
                 * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
                 * */
                const month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                const day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                const hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                const minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                const seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                // 拼接
                return year + "-" + month + "-" + day + ' ' + hours + ':' + minutes + ':' + seconds;
            },

            fInit() {
                let self = this
                let params = new URLSearchParams();
                params.append('CMD', "AT");
                axios.post('/f_wscl/com2', params)
                    .then(function (res) {
                        //--db1左边表结构的树
                        let {db3} = res.data

                        self.tableShang.push({VALUE01: '全部', VALUE02: '全部', VALUE03: '全部'})
                        for (let i = 0; i < db3.length; i++) {
                            self.tableShang.push(db3[i])
                        }
                        self.sh = '全部'
                    })
                    .catch(function (error) {
                        layer.msg('网络异常错误', {icon: 1, time: 1000});
                    });
            },
        },
        mounted() {
            this.fInit()
        },
        created() {
            let windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
            this.tableHeightL = windowHeight - 85;
            // this.dateBb = this.dateFormat(new Date())
            // this.dateEe = this.dateFormat(new Date())

            //当前设定的日期时间
            let d = new Date
            let year1,month1,day1, h1,f1,m1;
            [year1,month1,day1,h1,f1,m1] = [d.getFullYear(),d.getMonth(),d.getDate(),d.getHours(),d.getMinutes(), d.getSeconds()]
            let date1 = new Date(year1, month1, day1,23,59,59)
            this.value2.push(date1)
            // //前一天设定的日期时间
            let year2,month2,day2
            d.setTime(d.getTime()-60*60*1000);
            [year2,month2,day2] = [d.getFullYear(),d.getMonth(),d.getDate()]
            let date2 = new Date(year2,month2,day2,0,0,0)
            this.value2.unshift(date2)
        }
    });

</script>

</body>
</html>
